<script language="javascript" type="text/javascript"
	src="<?php echo $this->load->config->item('base_url') . $this->load->config->item('inc_folder'); ?>scripts/jquery-2.0.3.js"></script>
<script type="text/javascript">
	$(function() {  
        $('#tglawal').datepicker({
			dateFormat:'yy-mm-dd',
			buttonImage:'assets/images/calendar.gif',
			buttonImageOnly : true,
			showOn : 'button'
		});  
    });  
	
	$(function() {  
        $('#tglakhir').datepicker({
			dateFormat:'yy-mm-dd',
			buttonImage:'assets/images/calendar.gif',
			buttonImageOnly : true,
			showOn : 'button'
		});  
    });  
</script>
<script type="text/javascript">
var qty = 0;
var amount = 0;
function hitungTotal(totalcont,val){
	//alert(totalcont.id);
	totalcont.value = (this.qty * this.amount);
}
function setQty(qty){
	this.qty = qty.value;
}
function setAmount(amt){
	this.amount = amt.value;
}

function onlyNumbers(evt) 
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		//status = "This field accepts numbers only."
		alert("Harus di Isi Angka");
		return false
	}
	//status = ""
	return true 	
}
</script>
<form method="post" name="frmSearch" action="<?php echo site_url('pembeliancontroller');?>">
    <table width="100%" cellpadding="3" cellspacing="0" border="1">
    	<tr>
            <td width="90"><strong>Tanggal</strong></td>
            <td><strong>:</strong></td>
            <td width="172"><input type="text"  name="tglawal" id="tglawal" maxlength="10" value="" style="width:110px;"/></td>
            <td width="30"><strong>S/D </strong></td>
            <td width="542"><input type="text"  name="tglakhir" id="tglakhir" maxlength="10" value="" style="width:110px;"/></td>
        </tr>
        <tr>
            <td width="127" height="42"><strong>Pilih Search</strong></td>
          <td width="16" align="center"><strong>:</strong></td>
            <td colspan="3">
                <select name="kdview">
                    <option value="0">Pilih</option>
                    <option value="1">Kode PO</option>
                    <option value="2">Nama Supplier</option>
                    <option value="3">Nama Barang</option>
                </select> &nbsp;|&nbsp;<input type="text"  name="namaview" id="namaview" size="50" />
            </td>
		</tr>
        <tr align="center">
        	<td colspan="5" height="25"><input type="submit" name="btnview" value="Search"></td>
    	</tr>
    </table>
</form>
<br />
<form method="post" name="frmSave" action="<?php echo site_url('pembeliancontroller/tambahpembelian');?>">
    <table width="100%" cellpadding="3" cellspacing="0" border="1">
    	<tr style="background-color:#FFF; color:#000000;" align="center">
        	<td colspan="3" height="25"><strong>INPUT PEMBELIAN</strong></td>
    	</tr>
        <tr >
        	<td colspan="3" height="25">&nbsp;</td>
    	</tr>
        <tr>
            <td width="166"><strong>Kode PO</strong></td>
            <td width="23" align="center"><strong>:</strong></td>
            <td width="781" colspan="3"><input type="text"  name="kdpo" id="kdpo" maxlength="12" size="25" value="{kodepono}" readonly="readonly" /></td>
        </tr>
        <tr>
            <td width="166"><strong>Nama supplier</strong></td>
            <td width="23" align="center"><strong>:</strong></td>
            <td ><select name="kdsupp">
                    <?php 
						$count = count($mastersupp);
                    	foreach($mastersupp as $comboInd)
						{
                    ?>
                    	<option value="<?php echo $comboInd->Kodesupplier?>"><?php echo $comboInd->suppliername;?></option>
                    <?php }?>
                </select></td>
        </tr>
        <tr>
            <td width="166"><strong>Keterangan</strong></td>
            <td width="23" align="center"><strong>:</strong></td>
            <td ><input type="text"  name="keterangan" id="keterangan" size="50" maxlength="100"/></td>
        </tr>        
	</table>
    <input type="button" id="btnAddingDiv" name="btnAddingDiv" value="Add Detail" />
    <br /><br />
    <div id="divrows">
    <div><table width="100%" cellpadding="3" cellspacing="0" border="1"><tr style="background-color:#FFF; color:#000000;" align="center"><td colspan="3" height="25"><strong>Detail Pembelian</strong></td></tr><tr><td width="131"><strong>Nama Barang</strong></td><td width="22" align="center"><strong>:</strong></td><td width="817" ><select name="kdbarang[]"><?php $count = count($masterbarang);foreach($masterbarang as $comboInd){?><option value="<?php echo $comboInd->KodeDetailBarang?>"><?php echo $comboInd->Productname;?></option><?php }?></select></td></tr><tr><td width="131"><strong>Harga Barang</strong></td><td width="22" align="center"><strong>:</strong></td><td ><input type="text" name="hrgbarang[]" id="hrgbarang[]" size="50" maxlength="11" onkeyup="javascript:setAmount(this);" onkeypress="return onlyNumbers(event);"/></td></tr><tr><td width="131"><strong>Quantity</strong></td><td width="22" align="center"><strong>:</strong></td><td ><input type="text" name="qty[]" id="qty[]" size="50" maxlength="4" onkeyup="javascript:setQty(this);" onkeypress="return onlyNumbers(event);"/></td></tr><tr><td width="131"><strong>Discount</strong></td><td width="22" align="center"><strong>:</strong></td><td ><input type="text"  name="distcoun[]" id="distcoun[]" size="50" maxlength="4"/></td></tr><tr><td width="131"><strong>Jumlah Harga</strong></td><td width="22" align="center"><strong>:</strong></td><td ><input type="text" name="jmlhhrg[]" id="jmlhhrg[]" class="flat-textbox" size="15" maxlength="11" onmousedown="javascript:hitungTotal(this,0);"/></td></tr></table></div><br/>
    </div>
    <table border="1" cellpadding="3" cellspacing="0" width="100%" style=" border-collapse: collapse;" class="record" bordercolor="#000000">
    	<tr class="cellDefault">
			<td colspan="11" align="center"><input type="submit" name="btnSave" value="Simpan"> &nbsp;|&nbsp; <input type="button" name="btnClose" value="Back" class="btn" onclick="javascript:window.location='<?php echo site_url('menuhomecontroller'); ?>';" /></td>
		</tr>
    </table>    
</form>
<br />
<br />
<div class="cleaner_h10"></div>
<table border="1" cellpadding="3" cellspacing="0" width="100%" style=" border-collapse: collapse;" class="record" bordercolor="#CCCCCC">
    <tr style="background-color:#FFF; color:#000000;" align="center">
        <td colspan="9" height="25"><strong>LIST PEMBELIAN</strong></td>
    </tr>
    <tr style="background-color:#333; color:#FFF;" align="center">
    	<td>Kode PO</td>
        <td>Tanggal PO</td>
        <td>Nama Supplier</td>
        <td>Nama Barang</td>
        <td>Harga Barang</td>
        <td>Quantity</td>
        <td>Discount</td>
        <td>Jumlah Harga</td>
        <td>&nbsp;</td>
    </tr>
	<?php if(count($transpo)>0){ ?>
        {transpo}
            <tr class="cellDefault">
                <td align="center">{NoPo}</td>
                <td align="center">{Tanggalpo}</td>
                <td align="center">{suppliername}</td>
                <td align="center">{Productname}</td>
                <td align="center">{HargaBarang}</td>
                <td align="center">{Quantity}</td>
                <td align="center">{Discount}</td>
                <td align="center">{Amount}</td>
                <td align="center">
                    <a href="<?php echo site_url('pembeliancontroller/ubahpembelian');?>/{NoPo}/{IDdetail}">Edit</a>
                    &nbsp;|&nbsp;
                <?php
                if($this->session->userdata('grade') == 0)
				{
				?>
                    <a href="<?php echo site_url('pembeliancontroller/deletepembelian');?>/{NoPo}/{IDdetail}">Delete</a>
				<?php } ?>
                </td>
            </tr>
        {/transpo}
    <?php } else{
            echo "<tr>";
            echo "<td colspan='9' style='text-align:center;color:red;'>No Data To Display</td>";
            echo "</tr>";
    } ?>
    <?php if(!empty($message))?>{message}
</table>
<?php echo $links; ?>